package hesso.smartdraw.ch.guielements;

import hesso.smartdraw.ch.DrawWallScreen;

import org.anddev.andengine.entity.primitive.Rectangle;
import org.anddev.andengine.input.touch.TouchEvent;

import android.util.Log;

public class SnapDot extends Rectangle{

	private DrawWallScreen sceneHost;
	private float x, y;
	private final String TAG = "SnapDot";

	public SnapDot(float x, float y, float size, DrawWallScreen hostScene) {		
		super(x - (size / 2), y - (size / 2), size, size);
		this.x = x;
		this.y = y;
		this.sceneHost = hostScene;
		this.setColor(1f, 0f, 0f);
		this.sceneHost.getScene().registerTouchArea(this);
	}	

	@Override
	public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY){
		switch(pSceneTouchEvent.getAction()) {
		case TouchEvent.ACTION_DOWN:
			return false;
		case TouchEvent.ACTION_MOVE:
			Log.d(TAG, "Moved!");			
			if(this.sceneHost.getTempWallRect() != null 
					&& this.sceneHost.getTempWallRect().getX1() != this.x
					&& this.sceneHost.getTempWallRect().getY1() != this.y){
				this.sceneHost.getTempWallRect().setPosition(
						this.sceneHost.getTempWallRect().getX1(), 
						this.sceneHost.getTempWallRect().getY1(), 
						this.x, 
						this.y);
				return true;
			}else{
				return false;
			}			
		case TouchEvent.ACTION_UP:
			return false;
		}
		return true;
	}


}
